package org.jash.sportnews2109.ui

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import org.jash.common.adapter.CommonAdapter
import org.jash.sportnews2109.BR
import org.jash.sportnews2109.R
import org.jash.sportnews2109.databinding.FragmentCommentBinding
import org.jash.sportnews2109.entity.Comment

class CommentFragment : BottomSheetDialogFragment(R.layout.fragment_comment) {
    var comment:Comment? = null
        set(value)  {
            field = value
            binding?.comment = value
            adapter.clear()
            adapter += comment?.replays ?: listOf()
        }
    var binding: FragmentCommentBinding? = null
    val adapter by lazy { CommonAdapter<Comment>(R.layout.replay_item, BR.comment) }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding = DataBindingUtil.bind(view)
        binding?.replays?.adapter = adapter
        if (comment != null) {
            binding?.comment = comment
            adapter.clear()
            adapter += comment?.replays ?: listOf()

        }
    }
}